<template>
	<view class="cu-modal bottom-modal" :class="{'show':isShow}" @click="hide">
		<view class="cu-dialog">
			<view class="goods-data">
				<view class="thumb">
					<image :src="image" mode="">
					</image>
				</view>
				<view class="item">
					<view class="title">
						<text></text>
					</view>
					<view class="price">
						<text class="min">￥</text>
						<text class="max">{{pinkPrice}}</text>
						<text class="min">.00</text>
					</view>
					<view class="inventory">
						<text>库存：{{stock}}</text>
						<text>每人限购：{{buyNumQuota}}</text>
					</view>
				</view>
			</view>
			<view class="attr-size">
				<view class="attr-number" @click.stop="onStop">
					<view class="tit">数量</view>
					<view class="number">
						<text class="iconfont icon-jian" @click="sub"></text>
						<input type="tel" v-model="num" maxlength="8">
						<text class="iconfont icon-jia" @click="add"></text>
					</view>
				</view>
			</view>

			<view class="attr-btn">
				<view class="confirm" v-if="BuyType === 1" @click="onConfirm(BuyType,5)">立即购买</view>
				<view class="confirm" v-if="BuyType === 2 || BuyType === 3" @click="onConfirm(BuyType,2)">确定</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		// props: ['image' , 'sku',],
		props: ['stock','peopleQuota','buyNumQuota','image' , 'skuId','pinkPrice'],
		data() {
			return {
				isShow: false,
				// 购买类型
				BuyType: 0,
				temp: [],
				price: '',
				num:1
			};
		},
		methods: {
            add(){
				var num = this.num
				var buyNumQuota = this.buyNumQuota;
				if(num < this.buyNumQuota){
					num++
				}else{
					console.log('已经到达上限')
					uni.showToast({
						title:'已经到达上限',
						duration: 2000
					})
				}
				this.num = num
			},
			sub(){
				var num = this.num
				num--
				if(num == 0 ){
					num =1
				}
				this.num = num
			},
			/**
			 * 显示 
			 * @param {Number} type 1 点击选择 2 加入购物 3 立即购买
			 * 1 单独购买 2 立即购买
			 */
			show(type) {
				this.BuyType = type;
				this.isShow = true;
			},
			hide() {
				this.isShow = false;
			},
			onStop() {

			},
			/**
			 * 确认点击
			 */
			//orderType 2:拼团购买  5:拼团单独购买
			onConfirm(type,orderType) {
				var skuIds = this.skuId
				var num =  this.num
				var price = this.pinkPrice;
				var totalPrice = num*price
				
				var url = '?skuIds='+skuIds+'&order_type_code='+ orderType +'&num='+num+'&totalPrice='+totalPrice
				uni.navigateTo({
					url: '/pages/Order/Order'+url,
				})
				return
			 // setTimeout(function(){
				 
			 // },500)
				
				
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'PinkNum.scss';
</style>
